package com.ruoyi.web.controller.saas;

import com.bonuo.saas.domain.Event;
import com.bonuo.saas.service.EventService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务事件Controller
 */
@Api(tags = "服务事件管理")
@RestController
@RequestMapping("/saas/event")
public class EventController extends BaseController {
    @Autowired
    private EventService eventService;

    /**
     * 查询服务事件列表
     */
    @ApiOperation(value = "查询服务事件列表")
    @GetMapping("/list")
    public AjaxResult list(Event event,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<Event> list = eventService.selectEventList(event);
        return success(new PageInfo<>(list));
    }

    /**
     * 新增服务事件
     */
    @ApiOperation(value = "新增服务事件")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Event event) {
        return toAjax(eventService.insertEvent(event));
    }

    /**
     * 修改服务事件
     */
    @ApiOperation(value = "修改服务事件")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Event event) {
        return toAjax(eventService.updateEvent(event));
    }

    /**
     * 删除服务事件
     */
    @ApiOperation(value = "删除服务事件")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        return toAjax(eventService.deleteEventById(id));
    }
}